package com.example.everying.controller.order;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.everying.annotation.WebLog;
import com.example.everying.context.UserContext;
import com.example.everying.model.dto.order.OrderInfoPageDto;
import com.example.everying.model.dto.order.TransferRecordDto;
import com.example.everying.model.vo.user.UserInfoVo;
//import com.example.everying.service.order.OrderInfoService;
import com.example.everying.service.order.TransferRecordService;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "订单")
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

//    @Autowired
//    private OrderInfoService orderInfoService;
    @Autowired
    private TransferRecordService transferRecordService;


//    @ApiOperation(value = "订单列表")
//    @PostMapping("page")
//    @WebLog(description = "订单列表")
//    public Result<?> recharge(@ApiParam(name = "OrderInfoPageDto", value = "订单列表请求参数", required = true)
//                              @RequestBody OrderInfoPageDto dto) {
//        Page<OrderInfoEntity> pageParam = new Page<>(dto.getPage(), dto.getLimit());
//        IPage<OrderInfoEntity> pageModel = orderInfoService.selectPage(pageParam, dto);
//        return Result.ok(pageModel);
//    }

    @ApiOperation(value = "用户转账")
    @PostMapping("transfer")
    @WebLog(description = "用户转账")
    public Result<?> transfer(@ApiParam(name = "TransferRecord", value = "用户转账请求参数", required = true)
                              @RequestBody TransferRecordDto record) {
        UserInfoVo userInfoVo = UserContext.getUser();
        if (userInfoVo == null) {
            return Result.fail("请先登录");
        }
        record.setFromUserId(userInfoVo.getId());
        return transferRecordService.addTransferRecord(record);
    }

}
